{#
This file is part of EC-CUBE

Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.

http://www.ec-cube.co.jp/

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#}
{% extends 'default_frame.twig' %}

{% set menus = ['order', 'order_master'] %}

{% block title %}受注管理{% endblock %}
{% block sub_title %}受注マスター{% endblock %}

{% form_theme searchForm 'Form/bootstrap_3_horizontal_layout.html.twig' %}

{% block stylesheet %}
<link rel="stylesheet" href="{{ app.config.admin_urlpath }}/assets/css/bootstrap-datetimepicker.min.css">
{% endblock stylesheet %}

{% block javascript %}
<script src="{{ app.config.admin_urlpath }}/assets/js/vendor/moment.min.js"></script>
<script src="{{ app.config.admin_urlpath }}/assets/js/vendor/moment-ja.js"></script>
<script src="{{ app.config.admin_urlpath }}/assets/js/vendor/bootstrap-datetimepicker.min.js"></script>
<script>
  $(function() {

    var inputDate = document.createElement('input');
    inputDate.setAttribute('type', 'date');
    if (inputDate.type !== 'date') {
      $('input[id$=_date_start]').datetimepicker({
        locale: 'ja',
        format: 'YYYY-MM-DD',
        useCurrent: false,
        showTodayButton: true
      });

      $('input[id$=_date_end]').datetimepicker({
        locale: 'ja',
        format: 'YYYY-MM-DD',
        useCurrent: false,
        showTodayButton: true
      });
    }


    // 登録チェックボックス
    $('#check-all').click(function() {
      var checkall = $('#check-all').prop('checked');
      if (checkall) {
        $('input[id^=check-]').prop('checked', true);
        } else {
        $('input[id^=check-]').prop('checked', false);
      }
    });

    $('#dropmenu ul a').click(function(event) {
      event.preventDefault();
      var href = $(this).attr('href');
      var isChecked = false;
      $('input[id^=check-]').each(function() {
        var check = $(this).prop('checked');
        if (check) {
          isChecked = true;
        }
      });
      if (!isChecked) {
        alert("チェックボックスが選択されていません");
        return false;
      }
      $('#dropdown-form').attr('action', href).submit();
        return false;
    });

    // フォーム値を確認し、アコーディオンを制御
    // 値あり : 開く / 値なし : 閉じる
    (function($, f) {
        //フォームがないページは処理キャンセル
        var $ac = $(".accpanel");
        if (!$ac) {
            return false
        }

        //フォーム内全項目取得
        var c = f();
        if (c.formState()) {
            if ($ac.css("display") == "none") {
                $ac.siblings('.toggle').addClass("active");
                $ac.slideDown(0);
            }
        } else {
            $ac.siblings('.toggle').removeClass("active");
            $ac.slideUp(0);
        }
    })($, formPropStateSubscriber);
});
</script>
{% endblock javascript %}

{% block main %}
<!--検索条件設定テーブルここから-->
<div id="search_wrap" class="search-box">
  <form name="search_form" id="search_form" method="post" action="{{ url('admin_order') }}">
    {{ form_widget(searchForm._token) }}
    <div id="search_box_main" class="row">
      <div id="search_box_main__body" class="col-md-12 accordion">
        {{ form_widget(searchForm.multi, { attr: { placeholder: '受注ID・注文者名・注文者会社名', class : 'input_search' } } ) }}

        <a href="#" class="toggle{% if active %} active{% endif %}">
          <svg class="cb cb-minus"> <use xlink:href="#cb-minus"/></svg> <svg class="cb cb-minus"> <use xlink:href="#cb-minus"/></svg>
        </a>
        <div id="search_box_main__body_toggle" class="search-box-inner accpanel" {% if active %} style="display: block;"{% endif %}>
          <div class="row">
            <div id="search_box_main__body_inner" class="col-sm-12 col-lg-10 col-lg-offset-1 search">

              <div class="row">
                <div class="col-sm-12">
                  <div id="search_box_main__multi_status" class="form-group">
                    <label>対応状況</label>
                    <div>
                      {{ form_widget(searchForm.multi_status) }}
                    </div>
                  </div>
                </div>
              </div><!-- /.row -->
              <div class="row">
                <div class="col-md-6">
                  <div id="search_box_main__name" class="form-group">
                    <label>お名前</label>
                    {{ form_widget(searchForm.name) }}
                  </div>
                </div>
                <div class="col-md-6">
                  <div id="search_box_main__kana" class="form-group">
                    <label>お名前(フリガナ)</label>
                    {{ form_widget(searchForm.kana) }}
                    {{ form_errors(searchForm.kana) }}
                  </div>
                </div>
              </div><!-- /.row -->
              <div class="row">
                <div class="col-sm-6">
                  <div id="search_box_main__tel" class="form-group">
                    <label>電話番号</label>
                    {{ form_widget(searchForm.tel) }}
                    {{ form_errors(searchForm.tel) }}
                  </div>
                </div>
                <div id="search_box_main__email" class="col-sm-6">
                  <label>メールアドレス</label>
                  <div class="form-group">
                    {{ form_widget(searchForm.email) }}
                    {{ form_errors(searchForm.email) }}
                  </div>
                </div>
              </div><!-- /.row -->

              <div class="row">
                <div class="col-xs-12">
                  <div id="search_box_main__sex" class="form-group">
                    <label>性別</label>
                    {{ form_widget(searchForm.sex) }}
                  </div>
                </div>
              </div><!-- /.row -->

              <div class="row">
                <div class="col-sm-12">
                  <div id="search_box_main__payment" class="form-group">
                    <label>支払方法</label>
                    <div>
                      {{ form_widget(searchForm.payment) }}
                    </div>
                  </div>
                </div>
              </div><!-- /.row -->

              <div class="row">
                <div id="search_box_main__order_date" class="col-sm-6">
                  <label>受注日</label>
                  <div class="form-group range">
                    {{ form_widget(searchForm.order_date_start, {'attr': {'class': 'input_cal'}}) }} ～ {{ form_widget(searchForm.order_date_end, {'attr': {'class': 'input_cal'}}) }}
                  </div>
                </div>
                <div id="search_box_main__payment_date" class="col-sm-6">
                  <label>入金日</label>
                  <div class="form-group range">
                    {{ form_widget(searchForm.payment_date_start, {'attr': {'class': 'input_cal'}}) }} ～ {{ form_widget(searchForm.payment_date_end, {'attr': {'class': 'input_cal'}}) }}
                  </div>
                </div>
              </div><!-- /.row -->

              <div class="row">
                <div id="search_box_main__commit_date" class="col-sm-6">
                  <label>発送日</label>
                  <div class="form-group range">
                    {{ form_widget(searchForm.commit_date_start, {'attr': {'class': 'input_cal'}}) }} ～ {{ form_widget(searchForm.commit_date_end, {'attr': {'class': 'input_cal'}}) }}
                  </div>
                </div>
                <div id="search_box_main__update_date" class="col-sm-6">
                  <label>更新日</label>
                  <div class="form-group range">
                    {{ form_widget(searchForm.update_date_start, {'attr': {'class': 'input_cal'}}) }} ～ {{ form_widget(searchForm.update_date_end, {'attr': {'class': 'input_cal'}}) }}
                  </div>
                </div>
              </div><!-- /.row -->

              <div class="row">
                <div class="col-sm-6">
                  <div id="search_box_main__payment_total" class="form-group range">
                    <label>購入金額</label>
                    {{ form_widget(searchForm.payment_total_start) }} ～ {{ form_widget(searchForm.payment_total_end) }}
                  </div>
                </div>
                <div class="col-md-6">
                  <div id="search_box_main__buy_product_name" class="form-group">
                    <label>購入商品名</label>
                    {{ form_widget(searchForm.buy_product_name) }}
                  </div>
                </div>
                  <div class="extra-form col-md-12">
                      {% for f in searchForm.getIterator %}
                          {% if f.vars.name matches '[^plg*]' %}
                            <div class="form-group">
                              {{ form_label(f) }}
                              {{ form_widget(f) }}
                              {{ form_errors(f) }}
                            </div>
                          {% endif %}
                      {% endfor %}
                  </div>

              </div><!-- /.row -->
              <div id="search_box_main__clear" class="row">
                <div class="col-sm-12">
                  <p class="text-center"><a href="#" class="search-clear">検索条件をクリア</a></p>
                </div>
              </div><!-- /.row -->
            </div>
          </div>
        </div>
      </div>
      <!-- /.col -->
    </div>
    <div id="search_box_footer" class="row btn_area">
      <div id="search_box_footer__button_area" class="col-xs-8 col-xs-offset-2 col-sm-4 col-sm-offset-4 text-center">
        <button type="submit" class="btn btn-primary btn-block btn-lg">
          検索する <svg class="cb cb-angle-right"> <use xlink:href="#cb-angle-right" /></svg>
        </button>
      </div>
      <!-- /.col -->
    </div>
  </form>
</div>
<!--検索条件設定テーブルここまで-->

{% if pagination %}
    <div id="result_list" class="row">
        <div class="col-md-12">
            <div id="result_list_main" class="box">
                {% if pagination.totalItemCount > 0 %}
                <div id="result_list_main__header" class="box-header with-arrow">
                    <h3 class="box-title">検索結果 <span class="normal"><strong>{{ pagination.totalItemCount }} 件</strong> が該当しました</span></h3>
                </div><!-- /.box-header -->
                <div id="result_list_main__body" class="box-body">
                    <div id="result_list_main__menu" class="row">
                        <div class="col-md-12">
                            <ul class="sort-dd">
                                <li id="result_list_main__pagemax_menu" class="dropdown">
                                    {% for pageMax in pageMaxis if pageMax.name == page_count %}
                                        <a id="result_list_main__pagemax_menu_toggle" class="dropdown-toggle" data-toggle="dropdown">{{ pageMax.name|e }}件<svg class="cb cb-angle-down icon_down"> <use xlink:href="#cb-angle-down" /></svg></a>
                                        <ul class="dropdown-menu">
                                    {% endfor %}
                                    {% for pageMax in pageMaxis if pageMax.name != page_count %}
                                            <li><a href="{{ path('admin_order_page', {'page_no': 1, 'page_count': pageMax.name}) }}">{{ pageMax.name|e }}件</a></li>
                                    {% endfor %}
                                        </ul>
                                </li>
                                <li id="result_list_main__csv_menu" class="dropdown">
                                    <a id="result_list_main__csv_menu_toggle" class="dropdown-toggle" data-toggle="dropdown">CSVダウンロード<svg class="cb cb-angle-down icon_down"> <use xlink:href="#cb-angle-down" /></svg></a>
                                    <ul class="dropdown-menu">
                                        <li><a href="{{ url('admin_order_export_order') }}">受注CSVダウンロード</a></li>
                                        <li><a href="{{ url('admin_order_export_shipping') }}">配送CSVダウンロード</a></li>
                                        <li><a href="{{ url('admin_setting_shop_csv', { id : constant('\\Eccube\\Entity\\Master\\CsvType::CSV_TYPE_ORDER') }) }}">受注CSV出力項目設定</a></li>
                                        <li><a href="{{ url('admin_setting_shop_csv', { id : constant('\\Eccube\\Entity\\Master\\CsvType::CSV_TYPE_SHIPPING') }) }}">配送CSV出力項目設定</a></li>
                                    </ul>
                                </li>
                                <li id="dropmenu" class="dropdown">
                                    <a id="result_list_main__other_menu_toggle"class="dropdown-toggle" data-toggle="dropdown">その他<svg class="cb cb-angle-down icon_down"> <use xlink:href="#cb-angle-down" /></svg></a>
                                    <ul class="dropdown-menu">
                                        <li><a href="{{ url('admin_order_mail_all') }}">メール一括通知</a></li>
                                    </ul>
                                </li>
                            </ul>
                        </div>
                    </div>
                    <form id="dropdown-form">
                    <div id="result_list_main__list" class="table_list">
                        <div id="result_list_main__list_body" class="table-responsive with-border">
                            <table class="table table-striped">
                                <thead>
                                    <tr id="result_list_main__header">
                                        <th class="text-center"><input type="checkbox" id="check-all"></th>
                                        <th id="result_list_main__header_order_date">受注日</th>
                                        <th id="result_list_main__header_id">注文番号</th>
                                        <th id="result_list_main__header_name">お名前</th>
                                        <th id="result_list_main__header_payment_method">支払方法</th>
                                        <th id="result_list_main__header_payment_total">購入金額(円)</th>
                                        <th id="result_list_main__header_commit_date">発送日</th>
                                        <th id="result_list_main__header_order_status">対応状況</th>
                                        <th>&nbsp;</th>
                                    </tr>
                                </thead>
                                <tbody>
                            {% for Order in pagination %}
                                    <tr id="result_list_main__item--{{ Order.id }}">
                                        <td id="result_list_main__id_check--{{ Order.id }}" class="text-center"><input type="checkbox" id="check-{{ Order.id }}" data-id="{{ Order.id }}" name="ids{{ Order.id }}"></td>
                                        <td id="result_list_main__order_date--{{ Order.id }}">{{ Order.order_date|date_format }}</td>
                                        <td id="result_list_main__id--{{ Order.id }}"><a href="{{ url('admin_order_edit', { id : Order.id }) }}">{{ Order.id }}</a></td>
                                        <td id="result_list_main__name--{{ Order.id }}">{{ Order.name01 }} {{ Order.name02 }}</td>
                                        <td id="result_list_main__payment_method--{{ Order.id }}">{{ Order.payment_method }}</td>
                                        <td id="result_list_main__payment_total--{{ Order.id }}" class="text-right">{{ Order.payment_total|number_format }}</td>
                                        <td id="result_list_main__commit_date--{{ Order.id }}">{{ Order.commit_date|date_format }}</td>
                                        <td id="result_list_main__order_status--{{ Order.id }}">{{ Order.OrderStatus }}</td>
                                        <td id="result_list_main__item_menu_box--{{ Order.id }}" class="icon_edit">
                                            <div id="result_list_main__item_menu--{{ Order.id }}" class="dropdown">
                                                <a id="result_list_main__item_menu_toggle--{{ Order.id }}" class="dropdown-toggle" data-toggle="dropdown"><svg class="cb cb-ellipsis-h"> <use xlink:href="#cb-ellipsis-h" /></svg></a>
                                                <ul id="result_list_main_item_menu--{{ Order.id }}" class="dropdown-menu dropdown-menu-right">
                                                <li><a href="{{ url('admin_order_edit', { id : Order.id }) }}">編集</a></li>
                                                <li><a href="{{ url('admin_order_delete', { id : Order.id }) }}" {{ csrf_token_for_anchor() }} data-method="delete" data-message="この受注情報を削除してもよろしいですか？">削除</a></li>
                                                <li><a href="{{ url('admin_order_mail', { id : Order.id }) }}">メール通知</a></li>
                                                </ul>
                                            </div>
                                        </td>
                                    </tr>
                            {% endfor %}
                                </tbody>
                            </table>
                        </div>
                    </div>
                    </form>
                </div><!-- /.box-body -->
                {% if pagination.totalItemCount > 0 %}
                    {% include "pager.twig" with { 'pages' : pagination.paginationData, 'routes' : 'admin_order_page' } %}
                {% endif %}
                {% else %}
                <div class="box-header with-arrow">
                    <h3 class="box-title">検索条件に該当するデータがありませんでした。</h3>
                </div><!-- /.box-header -->
                {% endif %}
            </div><!-- /.box -->
        </div><!-- /.col -->
    </div>

{% endif %}

{% endblock %}
